<template>
	<comRoot>
		<template #page>
			<image v-if="commonConfigs && commonConfigs.domainFrontFileLink"
				:src="`${commonConfigs.domainFrontFileLink}/files/images/page-bg.png`" class="bg" />
				
			<image v-if="commonConfigs && commonConfigs.domainFrontFileLink" 
				:src="`${commonConfigs.domainFrontFileLink}/files/images/rebates/day-bg.png`" 
				style="width: 100%;height: 556rpx;"
				class="bg" />
				
			<comDetailNavigateBack title="每日奖励"/>	
			
			<view class="day-rebate-page relative">
				<view class="day-rebate-content relative" :style="{
						height: 'calc(100vh - ' + commonNavHeight + ')',
					}">
					<view class="day-rebate-box margin-auto relative">
						<view class="day-time absolute">
							<!-- <image class="bg" v-if="commonConfigs && commonConfigs.domainFrontFileLink" 
								:src="`${commonConfigs.domainFrontFileLink}/files/images/rebates/day-time-bg.png`" mode=""></image> -->
							<view class="relative">
								<text>活动时间：</text>
								<text class="font-hanserif-regular" style="color: #FFFFFF;">{{ countdownTimer }}</text>
							</view>
						</view>
						
						<view class="rebate-desc absolute">
							<image class="bg"
								v-if="commonConfigs && commonConfigs.domainFrontFileLink"
								:src="`${commonConfigs.domainFrontFileLink}/files/images/rebates/rebate-desc-bg.png`" mode=""></image>
							
							<view class="rebate-remark relative flex-align-items-center" v-html="dayRebateInfo.remarks"></view>
						</view>
						
						<view class="rebate-process absolute flex-direction-column flex-all-center">
							<image class="bg" v-if="commonConfigs && commonConfigs.domainFrontFileLink"
								:src="`${commonConfigs.domainFrontFileLink}/files/images/rebates/day-content-bg.png`" mode=""></image>
								
							<view class="relative rebate-process-nums flex-all-center" style="color: #FFF;">
								<!-- <image v-if="commonConfigs && commonConfigs.domainFrontFileLink"
									style="height: 44rpx;margin-right: 10rpx;"
									:src="`${commonConfigs.domainFrontFileLink}/files/images/user/currency-icon.png`" mode="heightFix"></image> -->
								<text>当前奖励比例：</text>
								<text style="color: #63FFF7;">{{ currentNumDesc }}</text>
							</view>
						
							<view class="rebate-process-infos">
								<view class="info-item flex-align-items-center relative flex-justify-content-between"
									v-for="(item, index) in (dayRebateInfo.showToday ? dayRebateInfo.configsToday : dayRebateInfo.configsYesterday)"
									v-if="dayRebateInfo && dayRebateInfo.configsYesterday && dayRebateInfo.configsYesterday.length" :key="index">
									
									<image class="bg" v-if="commonConfigs && commonConfigs.domainFrontFileLink && item.status" 
										:src="`${commonConfigs.domainFrontFileLink}/files/images/rebates/day-item-bg.png`" mode=""></image>
									
									<view class="relative flex-all-center">
										<view class="info-item-order relative flex-all-center">
											<image v-if="item.status" class="bg" 
												:src="`${commonConfigs.domainFrontFileLink}/files/images/rebates/current-day-sort-bg.png`" 
												mode=""></image>
											<image v-else class="bg"
												:src="`${commonConfigs.domainFrontFileLink}/files/images/rebates/day-sort-bg.png`" 
												mode=""></image>
											<view class="relative" :style="{
												color: item.status ? '#FFFFFF' : '#FFFFFF'
											}">
												{{ index + 1 }}
											</view>
										</view>
										<view class="info-item-des relative">{{ item.des }}</view>
									</view>
									
									<text class="info-item-txt relative">{{ item.txt }}</text>
								</view>
							</view>
						</view>
						
					</view>
					
					<view class="rebate-btns flex-justify-content-between font-hanserif-bold">
						<!-- <view class="rebate-btn-num flex-all-center">
							<image class="money-icon" v-if="commonConfigs && commonConfigs.domainFrontFileLink" :src="`${commonConfigs.domainFrontFileLink}/files/images/common/gaorebi-icon.png`" 
							style="height: 80rpx;"
							mode="heightFix"></image>
							<text class="num font-hanserif-bold">x{{ dayRebateInfo.moneyToday || 0 }}</text>
						</view> -->
						
						<view class="money-icon-nums flex-all-center relative">
							<image class="bg" 
								v-if="commonConfigs && commonConfigs.domainFrontFileLink" 
								:src="`${commonConfigs.domainFrontFileLink}/files/images/rebates/day-bg-left.png`" mode=""></image>
								
							<view class="money-icon-txt relative flex-all-center flex-direction-column">
								<view class="money-icon-txt-title">今日消费：</view>
								<view>{{ dayRebateInfo.cashToday }}</view>
							</view>
						</view>
						
						<view class="money-icon-nums flex-all-center relative">
							<image class="bg"
								v-if="commonConfigs && commonConfigs.domainFrontFileLink" 
								:src="`${commonConfigs.domainFrontFileLink}/files/images/rebates/day-bg-right.png`" mode=""></image>
								
							<view class="money-icon-txt relative flex-all-center flex-direction-column">
								<view class="money-icon-txt-title">昨日消费：</view>
								<view>{{ dayRebateInfo.cashYesterday }}</view>
							</view>
						</view>
					</view>
					
					<view :class="['money-oper-btn', 'margin-auto', 'relative', 'flex-all-center']">
						<image class="bg" v-if="commonConfigs && commonConfigs.domainFrontFileLink" :src="`${commonConfigs.domainFrontFileLink}/files/images/rebates/page-bottom-btn-bg.png`" mode=""></image>
						
						<view
							:class="['relative', 'font-hanserif-bold', 'day-btn-text', 'flex-all-center', !dayRebateInfo.redTag ? 'grayBg' : '']"
							@click="setCompleteFun">
							<image class="bg" v-if="commonConfigs && commonConfigs.domainFrontFileLink" :src="`${commonConfigs.domainFrontFileLink}/files/images/rebates/day-btn.png`" mode=""></image>
							<view class="relative">
								可领取飞机币*{{ dayRebateInfo.showToday ? dayRebateInfo.moneyToday : dayRebateInfo.moneyYesterday }}
							</view>
						</view>
					</view>
				</view>
			</view>
		</template>
	</comRoot>
</template>

<script>
	import {
		getActivityIndexApi,
		getActivityDoneApi
	} from '@/setupproject/INTERFACE.js';
	
	import {
		setCountFunDown
	} from '@/setupproject/TOOLS_FUN';
	
	export default {
		name: 'dayRebatePage',
		data() {
			return {
				timer: null,
				countdownTimer: '-- : -- : --',
				dayRebateInfo: {},
				isShowInfo: true,
				currentNumDesc: '0%',
			}
		},
		computed: {
			commonNavHeight() {
				return this.$store.getters.commonNavHeight + 'px';
			},
			commonConfigs() {
				return this.$store.getters.commonConfigs || {};
			},
		},
		onLoad() {
			this.timer = setInterval(() => {
				this.countdownTimer = setCountFunDown();
			}, 1000);
			this.getDataListFun();
		},
		onUnload() {
			// 清除倒计时定时器
			if(this.timer) {  
				clearInterval(this.timer);  
				this.timer = null;  
			}
		},
		methods: {
			async getDataListFun() {
				const {
					data,
					code,
				} = await getActivityIndexApi();
				
				if (code !== 200 && data) return false;
				
				this.dayRebateInfo = data;
				if(this.dayRebateInfo && this.dayRebateInfo.showToday) {
					this.dayRebateInfo.configsToday.map(item => {
						if(item.status) {
							this.currentNumDesc = item.txt;
						}
					})
				}else{
					this.dayRebateInfo.configsYesterday.map(item => {
						if(item.status) {
							this.currentNumDesc = item.txt;
						}
					})
				}
			},
			
			async setCompleteFun() {
				const { data, code, msg } = await getActivityDoneApi();
				
				if (code !== 200) {
					return uni.showToast({
						icon: 'none',
						title: msg
					});
				}
				
				uni.showToast({
					icon: 'success',
					title: msg
				});
				
				this.getDataListFun();
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.day-rebate-page {
		.day-rebate-content{
			padding-bottom: 180rpx;
			overflow-y: auto;
			.day-rebate-box {
				font-size: 24rpx;
				color: #fff;
				width: 710rpx;
				height: 836rpx;
				margin-top: 294rpx;
				.day-time {
					left: 0rpx;
					top: -180rpx;
					font-size: 28rpx;
					width: 403rpx;
					height: 56rpx;
					line-height: 56rpx;
					color: #FFFFFF;
					padding-left: 35rpx;
				}
				
				.rebate-desc {
					left: 0;
					top: -84rpx;
					width: 100%;
					height: 214rpx;
					padding: 10rpx 24rpx; 
					.rebate-remark {
						height: 214rpx;
						overflow-y: auto;
						// margin-top: 8rpx;
					}
				}
				
				.rebate-process {
					left: 0;
					top: 150rpx;
					width: 686rpx;
					height: 632rpx;
					
					.rebate-process-nums {
						width: 100%;
						height: 80rpx;
						font-size: 32rpx;
					}

					.rebate-process-infos {
						border-radius: 20rpx;
						// left: 0rpx;
						// top: 42rpx;
						// padding: 20rpx 3rpx 0;
						width: 649rpx;
						// height: 100%;
						background: rgba(255, 255, 255, 0.2);
						
						.info-item {
							width: 100%;
							height: 100rpx;
							padding: 0 18rpx;
							color: #FFFFFF;
							font-size: 32rpx;
							
							&::after {
								width: 100%;
								height: 2rpx;
								background: #FFFFFF;
								content: '';
								position: absolute;
								left: 0;
								right: 0;
								bottom: 0;
								margin: auto;
							}
							
							.info-item-order {
								margin-right: 10rpx;
								width: 52rpx;
								height: 50rpx;
							}
							.info-item-des {
								white-space: nowrap;
								width: 242rpx;
								margin-right: 10rpx;
								font-size: 28rpx;
							}
							.info-item-txt {
								white-space: nowrap;
								text-align: right;
							}
						}
					}
				}
				
			}
			
			.rebate-btns {
				width: 710rpx;
				left: 0;
				right: 0;
				margin: auto;
				
				.rebate-btn-num {
					margin-bottom: 10rpx;
					.money-icon {
						margin-right: 20rpx;
						width: 60rpx;
						height: 60rpx;
					}
					font-weight: bold;
					font-size: 60rpx;
					color: #FFDA4D;
				}
				
				.money-icon-nums {
					width: 345rpx;
					height: 110rpx;
					
					.money-icon-txt {
						color: #63FFF7;
						font-size: 28rpx;
						width: 100%;
						height: 100%;
						
						.money-icon-txt-title {
							font-size: 32rpx;
							color: #2D3489;
						}
					}
				}
			}
			
			
			.money-oper-btn {
				position: fixed;
				bottom: 0;
				width: 100%;
				height: 172rpx;
				color: #4470FF;
				font-size: 32rpx;
				
				.day-btn-text {
					width: 650rpx;
					height: 96rpx;
					line-height: 100%;
					
					&.grayBg {
						color: #FFFFFF;
						-webkit-filter: grayscale(100%);
						filter: grayscale(100%);
					}
				}
				
			}
		}
	}
</style>